package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.Action;
import javax.swing.KeyStroke;

import com.mrogrape.notepad.activity.action.NotepadAction;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.editor.TextEditor;

/**
 * 跳转到行
 * @author 110046
 *
 */
public class GotoLineMenuItemAction extends NotepadAction {

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public GotoLineMenuItemAction(){

		super.putValue(Action.NAME, "Go to Line");
		super.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK));
		super.putValue(Action.SHORT_DESCRIPTION, "Clear all contents of current editor.");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		TextEditor editor = ViewContext.getMainFrame().getCurrentTextEditor();

		if(editor == null){
			return;
		}
		
		int lineCount = editor.getLineCount();
		if(lineCount <= 1){
			return;
		}
		
		ViewContext.getGotoLineDialog().showDialog(editor);
	}
}
